package net.wantongtech.xa.uploadbasicinfo.dao;

import com.wtkj.dao.impl.BaseDataTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 处理缺失交易包的数据DAO
 *
 * @author MaShibo
 * 日期 :  2020/2/2
 */
@Repository
public class DealWithMissingTransPackageDao extends BaseDataTemplate {


    /**
     * 查询缺失文件的接收表记录ID
     *
     * @return ID集合
     */
    public List<String> queryMissingTransPackageReceiveId() {
        /*final String sql =
                "SELECT a.listid\n" +
                        "  FROM tq_interactionorgmsgreceive a\n" +
                        "  LEFT JOIN tq_interactionorgmsgerror e\n" +
                        "    ON e.receivelistid = a.listid\n" +
                        " WHERE a.state = 2\n" +
                        "   AND a.storeflag = 1\n" +
                        "   AND e.error LIKE '%获取文件内容失败%'";*/
        /*final String sql =
                "SELECT a.listid\n" +
                        "  FROM tq_interactionorgmsgreceive a\n" +
                        "  LEFT JOIN tq_interactionorgmsgerror e\n" +
                        "    ON e.receivelistid = a.listid\n" +
                        " WHERE a.state = 2\n" +
                        "   AND a.bizcode = 61011002\n" +
                        "   AND a.storeflag = 1\n" +
                        "   AND e.error LIKE '%获取文件内容失败%'\n" +
                        " ORDER BY a.createon DESC";*/
        /*final String sql =
                " SELECT a.listid\n" +
                        "   FROM tq_interactionorgmsgreceive a\n" +
                        "   LEFT JOIN tq_interactionorgmsgerror e\n" +
                        "     ON a.listid = e.receivelistid\n" +
                        "  WHERE a.bizcode = 61011003\n" +
                        "    AND a.state = 2\n" +
                        "    AND e.error LIKE '%获取文件内容失败%'\n" +
                        "    AND a.storeflag = 1\n" +
                        "    AND a.storepath IS NOT NULL\n" +
                        "  ORDER BY a.createon\n";*/
        /*final String sql = " SELECT a.listid\n" +
                "   FROM tq_interactionorgmsgreceive a\n" +
                "   LEFT JOIN tq_interactionorgmsgerror e\n" +
                "     ON a.listid = e.receivelistid\n" +
                "  WHERE a.bizcode = 61011004\n" +
                "    AND a.state = 2\n" +
                "    AND a.storepath IS NOT NULL\n" +
                "    AND a.storeflag = 1\n" +
                "    AND e.error LIKE '%获取文件内容失败'";*/
        /*final String sql = "SELECT a.listid\n" +
                "  FROM tq_interactionorgmsgreceive a\n" +
                "  LEFT JOIN tq_interactionorgmsgerror e\n" +
                "    ON a.listid = e.receivelistid\n" +
                " WHERE a.bizcode = 61011022\n" +
                "   AND a.state = 2\n" +
                "   AND a.storeflag = 1\n" +
                "   AND e.error LIKE '%从FastDfs加载原始交易包失败%'";*/
        final String sql = "SELECT a.listid\n" +
                "  FROM tq_interactionorgmsgreceive a\n" +
                "  LEFT JOIN tq_interactionorgmsgerror e\n" +
                "    ON a.listid = e.receivelistid\n" +
                " WHERE a.bizcode = 61011005\n" +
                "   AND a.state = 2\n" +
                "   AND a.storepath IS NOT NULL\n" +
                "   AND a.storeflag = 1\n" +
                "   AND e.error LIKE '%获取文件内容失败%'";
        return jdbcTemplate.queryForList(sql, String.class);
    }


    /**
     * 查询无法从硬盘获取文件内容的接收表记录
     *
     * @return ID集合
     */
    public List<String> queryDiskMissingTransPackageReceiveId() {
        /*final String sql =
                "SELECT a.listid\n" +
                        "  FROM tq_interactionorgmsgreceive a\n" +
                        "  LEFT JOIN tq_interactionorgmsgerror e\n" +
                        "    ON e.receivelistid = a.listid\n" +
                        " WHERE a.state = 2\n" +
                        "   AND a.storepath LIKE 'D:\\downloadFilePath%'\n" +
                        "   AND e.error LIKE '%获取文件内容失败%'";*/
        final String sql = "SELECT a.listid\n" +
                "  FROM tq_interactionorgmsgreceive a\n" +
                "  LEFT JOIN tq_interactionorgmsgerror e\n" +
                "    ON a.listid = e.receivelistid\n" +
                " WHERE a.bizcode = 61011022\n" +
                "   AND a.state = 2\n" +
                "   AND a.storeflag = 2\n" +
                "   AND e.error LIKE '%从硬盘加载原始交易包失败%'";
        return jdbcTemplate.queryForList(sql, String.class);
    }

}
